package at.fhj.itm09.snake.logic;

import android.os.Handler;
import android.os.Message;
import at.fhj.itm09.snake.views.SnakeView;

/**
 * @author Susanne Brandstätter - Susanne.Brandstaetter.ITM09@fh-joanneum.at
 * @author Katharina Biela - Katharina.Biela.ITM09@fh-joanneum.at
 * 
 * A simple Handler which we can use for the animation of the snake. 
 * We can use the sleep() function for the milliseconds of waiting
 * until the snakes becomes drawed again. 
 */

public class RefreshHandler extends Handler {
	
	private SnakeView snakeView;
	
	public RefreshHandler(SnakeView snakeView){
		this.snakeView = snakeView;
	}
    
    public void handleMessage(Message msg) {
        snakeView.update();
        snakeView.invalidate();
    }

    public void sleep(long delayMillis) {
        this.removeMessages(0);
        sendMessageDelayed(obtainMessage(0), delayMillis);
    }
};
